home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / rpc / rpcTest.c < prev    next >
C/C++ Source or Header  |  1990-10-02  |  10KB  |  392 lines

  1. /*
  2.  * rpcTest.c --
  3.  *
  4.  *    These are some utility routines that exercise the RPC system.
  5.  *
  6.  * Copyright (C) 1985 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /sprite/src/kernel/rpc/RCS/rpcTest.c,v 9.3 90/10/02 16:30:32 mgbaker Exp $ SPRITE (Berkeley)";
  12. #endif /* not lint */
  13.  
  14. #include <sprite.h>
  15. #include <stdio.h>
  16. #include <bstring.h>
  17. #include <rpc.h>
  18. #include <rpcTrace.h>
  19. #include <rpcSrvStat.h>
  20. #include <rpcCltStat.h>
  21. #include <time.h>
  22. #include <timer.h>
  23. #include <proc.h>
  24. #include <stdlib.h>
  25.  
  26.  
  27. /*
  28.  *----------------------------------------------------------------------
  29.  *
  30.  * Rpc_GetTime --
  31.  *
  32.  *    Get the time of day (in seconds since 1970) from the
  33.  *    specified server.
  34.  *
  35.  * Results:
  36.  *    The status code from the RPC. 0 means all went well.
  37.  *
  38.  * Side effects:
  39.  *    Fill in the time argument with the value returned from
  40.  *    the server.  The time is cleared to zeros if there is
  41.  *    an status from the server.
  42.  *
  43.  *----------------------------------------------------------------------
  44.  */
  45. ReturnStatus
  46. Rpc_GetTime(serverId, timePtr, timeZoneMinutesPtr, timeZoneDSTPtr)
  47.     int serverId;
  48.     Time *timePtr;
  49.     int *timeZoneMinutesPtr;
  50.     int *timeZoneDSTPtr;
  51. {
  52.     Rpc_Storage storage;
  53.     ReturnStatus status;
  54.     struct RpcTimeReturn {
  55.     Time    time;
  56.     int    timeZoneMinutes;
  57.     int    timeZoneDST;
  58.     } rpcTimeReturn;
  59.  
  60.     storage.requestDataPtr = (Address)NIL;
  61.     storage.requestDataSize = 0;
  62.  
  63.     storage.requestParamPtr = (Address)NIL;
  64.     storage.requestParamSize = 0;
  65.  
  66.     storage.replyDataPtr = (Address)NIL;
  67.     storage.replyDataSize = 0;
  68.  
  69.     storage.replyParamPtr = (Address)&rpcTimeReturn;
  70.     storage.replyParamSize = sizeof(rpcTimeReturn);
  71.  
  72.     status = Rpc_Call(serverId, RPC_GETTIME, &storage);
  73.     if (status) {
  74.     timePtr->seconds = 0;
  75.     timePtr->microseconds = 0;
  76.     *timeZoneMinutesPtr = 0;
  77.     *timeZoneDSTPtr = 0;
  78.     } else {
  79.     *timePtr = rpcTimeReturn.time;
  80.     if (rpcTimeReturn.timeZoneMinutes > 0) {
  81.         /*
  82.          * This is a return from lust, and timeZoneMinutes are
  83.          * really a unix kernel's tz_minuteswest, and the timeZoneDST
  84.          * is a code for what kind of time zone correction to use.
  85.          */
  86.         printf("Warning: Rpc_Start, negative timezone offset.\n");
  87.         *timeZoneMinutesPtr = -rpcTimeReturn.timeZoneMinutes;
  88.         *timeZoneDSTPtr = TRUE;
  89.     } else {
  90.         *timeZoneMinutesPtr = rpcTimeReturn.timeZoneMinutes;
  91.         *timeZoneDSTPtr = rpcTimeReturn.timeZoneDST;
  92.     }
  93.     }
  94.     return(status);
  95. }
  96.  
  97. /*
  98.  *----------------------------------------------------------------------
  99.  *
  100.  * Rpc_EchoTest --
  101.  *
  102.  *    Conduct a series of Echoes off the specified server.
  103.  *
  104.  * Results:
  105.  *    The status code from the RPC.
  106.  *
  107.  * Side effects:
  108.  *    Those of Rpc_Echo
  109.  *
  110.  *----------------------------------------------------------------------
  111.  */
  112. ReturnStatus
  113. Rpc_EchoTest(serverId, numEchoes, size, inputPtr, returnPtr, deltaTimePtr)
  114.     int serverId;
  115.     int numEchoes;
  116.     int size;
  117.     Address inputPtr;
  118.     Address returnPtr;
  119.     Time *deltaTimePtr;        /* Return: the average time per RPC.  If
  120.                  * this is a NIL pointer then the results
  121.                  * are printed to the console */
  122. {
  123.     int            packetCount;
  124.     ReturnStatus    status;
  125.     Timer_Ticks        startTime;
  126.     Timer_Ticks        endTime;
  127.     Time        diff;
  128.     Address        localInBuffer;
  129.     Address        localOutBuffer;
  130.  
  131.     localInBuffer = malloc(size);
  132.     bcopy(inputPtr, localInBuffer, size);
  133.     localOutBuffer = malloc(size);
  134.  
  135. #ifdef notdef
  136.     /*
  137.      * These statistics, the overall packet loss and retries, is
  138.      * computable by the user program using the Rpc_Stat system call.
  139.      */
  140.     Rpc_StartSrvTrace();
  141.     Rpc_EnterProcess();      /* for tracing */
  142. #endif /* notdef */
  143.  
  144.     if (deltaTimePtr == (Time *)NIL) {
  145.     printf("Echoing %d %d-byte messages\n", numEchoes, size);
  146.     }
  147.                  
  148.     Timer_GetCurrentTicks(&startTime);
  149.     packetCount = 0;
  150.     do {
  151.         packetCount++;
  152.         status = Rpc_Echo(serverId, localInBuffer, localOutBuffer, size);
  153.     } while ((status == SUCCESS) && (packetCount < numEchoes));
  154.  
  155.     Timer_GetCurrentTicks(&endTime);
  156.  
  157.     if ((deltaTimePtr == (Time *)NIL) && (status != SUCCESS)) {
  158.         printf("got error %x from Rpc_Echo\n", status);
  159.     }
  160.  
  161.     /*
  162.      * Compute time per RPC.
  163.      */
  164.     Timer_SubtractTicks(endTime, startTime, &endTime);
  165.     Timer_TicksToTime(endTime, &diff);
  166.     Time_Divide(diff, packetCount, &diff);
  167.     if (deltaTimePtr == (Time *)NIL) {
  168.     printf("time per RPC %d.%06d\n",
  169.                         diff.seconds, diff.microseconds);
  170.     } else {
  171.     *deltaTimePtr = diff;
  172.     }
  173. /*
  174.  * Hack alert. Cache the last value of delta time for the RPC's.
  175.  */
  176.     rpcDeltaTime = diff;
  177.  
  178. #ifdef notdef
  179.     Rpc_LeaveProcess();      /* for tracing */
  180.     Rpc_EndSrvTrace();
  181. #endif /* notdef */
  182.  
  183.     bcopy(localOutBuffer, returnPtr, size);
  184.     free(localOutBuffer);
  185.     free(localInBuffer);
  186.     return(status);
  187. }
  188.  
  189. /*
  190.  *----------------------------------------------------------------------
  191.  *
  192.  * Rpc_SendTest --
  193.  *
  194.  *    Send a bunch of packets to a server and time it.
  195.  *
  196.  * Results:
  197.  *    The status code from the RPC.
  198.  *
  199.  * Side effects:
  200.  *    Send off packets to the server.
  201.  *
  202.  *----------------------------------------------------------------------
  203.  */
  204. ReturnStatus
  205. Rpc_SendTest(serverId, numSends, size, inputPtr, deltaTimePtr)
  206.     int serverId;
  207.     int numSends;
  208.     int size;
  209.     Address inputPtr;
  210.     Time *deltaTimePtr;    /* Return: the average time per RPC.  If this is
  211.              * a NIL pointer then the results are printed to
  212.              * the console instead. */
  213. {
  214.     int            packetCount;
  215.     ReturnStatus    status;
  216.     Timer_Ticks        startTime;
  217.     Timer_Ticks        endTime;
  218.     Time        diff;
  219.     Address        localInBuffer;
  220.  
  221.     localInBuffer = malloc(size);
  222.     bcopy(inputPtr, localInBuffer, size);
  223.  
  224. #ifdef notdef
  225.     Rpc_StartSrvTrace();
  226.     Rpc_EnterProcess();      /* for tracing */
  227. #endif /* notdef */
  228.  
  229.     if (deltaTimePtr == (Time *)NIL) {
  230.     printf("Sending %d %d-byte messages\n", numSends, size);
  231.     }
  232.                  
  233.     Timer_GetCurrentTicks(&startTime);
  234.     packetCount = 0;
  235.     do {
  236.         packetCount++;
  237.         status = Rpc_Send(serverId, localInBuffer, size);
  238.     } while ((status == SUCCESS) && (packetCount < numSends));
  239.  
  240.     Timer_GetCurrentTicks(&endTime);
  241.  
  242.     if ((deltaTimePtr == (Time *)NIL) && (status != SUCCESS)) {
  243.         printf("got error %x from Rpc_Send\n", status);
  244.     }
  245.  
  246.     /*
  247.      * Compute time per RPC.
  248.      */
  249.     Timer_SubtractTicks(endTime, startTime, &endTime);
  250.     Timer_TicksToTime(endTime, &diff);
  251.     Time_Divide(diff, packetCount, &diff);
  252.     if (deltaTimePtr == (Time *)NIL) {
  253.     printf("time per RPC %d.%06d\n",
  254.                         diff.seconds, diff.microseconds);
  255.     } else {
  256.     *deltaTimePtr = diff;
  257.     }
  258. /*
  259.  * Hack alert. Cache the last value of delta time for the RPC's.
  260.  */
  261.     rpcDeltaTime = diff;
  262. #ifdef notdef
  263.     Rpc_LeaveProcess();      /* for tracing */
  264.     Rpc_EndSrvTrace();
  265. #endif /* notdef */
  266.  
  267.     free(localInBuffer);
  268.     return(status);
  269. }
  270.  
  271. /*
  272.  *----------------------------------------------------------------------
  273.  *
  274.  * Rpc_Echo --
  275.  *
  276.  *    Bounce data off of the specified server.
  277.  *
  278.  * Results:
  279.  *    The status code from the RPC.
  280.  *
  281.  * Side effects:
  282.  *    If the RPC is successful the input data is copied into
  283.  *    the return data.  This is an expensive copy...
  284.  *
  285.  *----------------------------------------------------------------------
  286.  */
  287. ReturnStatus
  288. Rpc_Echo(serverId, inputPtr, returnPtr, size)
  289.     int serverId;
  290.     Address inputPtr;
  291.     Address returnPtr;
  292.     int size;
  293. {
  294.     Rpc_Storage storage;
  295.     ReturnStatus status;
  296.  
  297.     storage.requestDataPtr = inputPtr;
  298.     storage.requestDataSize = size;
  299.  
  300.     storage.replyDataPtr = returnPtr;
  301.     storage.replyDataSize = size;
  302.  
  303.     storage.replyParamPtr = (Address)NIL;
  304.     storage.replyParamSize = 0;
  305.  
  306.     storage.requestParamPtr = (Address)NIL;
  307.     storage.requestParamSize = 0;
  308.  
  309.     status = Rpc_Call(serverId, RPC_ECHO_2, &storage);
  310.     return(status);
  311. }
  312.  
  313. /*
  314.  *----------------------------------------------------------------------
  315.  *
  316.  * Rpc_Ping --
  317.  *
  318.  *    Ping a remote host by doing a low level echo RPC.  The RPC
  319.  *    is handled at interrupt level by the remote host for minimal impact.
  320.  *
  321.  * Results:
  322.  *    The status code from the RPC.
  323.  *
  324.  * Side effects:
  325.  *    If the RPC is successful the input data is copied into
  326.  *    the return data.  This is an expensive copy...
  327.  *
  328.  *----------------------------------------------------------------------
  329.  */
  330. ReturnStatus
  331. Rpc_Ping(serverId)
  332.     int serverId;
  333. {
  334.     Rpc_Storage storage;
  335.     ReturnStatus status;
  336.  
  337.     storage.requestDataPtr = (Address)NIL;
  338.     storage.requestDataSize = 0;
  339.     storage.replyDataPtr = (Address)NIL;
  340.     storage.replyDataSize = 0;
  341.     storage.replyParamPtr = (Address)NIL;
  342.     storage.replyParamSize = 0;
  343.     storage.requestParamPtr = (Address)NIL;
  344.     storage.requestParamSize = 0;
  345.  
  346.     /*
  347.      * This should use RPC_ECHO_1, but it is unimplemented by the server.
  348.      */
  349.     status = Rpc_Call(serverId, RPC_ECHO_2, &storage);
  350.     return(status);
  351. }
  352.  
  353. /*
  354.  *----------------------------------------------------------------------
  355.  *
  356.  * Rpc_Send --
  357.  *
  358.  *    Send data to the specified server.
  359.  *
  360.  * Results:
  361.  *    The status code from the RPC.
  362.  *
  363.  * Side effects:
  364.  *    Send the request to the server...
  365.  *
  366.  *----------------------------------------------------------------------
  367.  */
  368. ReturnStatus
  369. Rpc_Send(serverId, inputPtr, size)
  370.     int serverId;
  371.     Address inputPtr;
  372.     int size;
  373. {
  374.     Rpc_Storage storage;
  375.     ReturnStatus status;
  376.  
  377.     storage.requestDataPtr = inputPtr;
  378.     storage.requestDataSize = size;
  379.  
  380.     storage.replyDataPtr = (Address)NIL;
  381.     storage.replyDataSize = 0;
  382.  
  383.     storage.replyParamPtr = (Address)NIL;
  384.     storage.replyParamSize = 0;
  385.  
  386.     storage.requestParamPtr = (Address)NIL;
  387.     storage.requestParamSize = 0;
  388.  
  389.     status = Rpc_Call(serverId, RPC_SEND, &storage);
  390.     return(status);
  391. }
  392.